package com.demo;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.junit.Test;

import business.common.SvcBigClientStatResultDto;
import business.common.SvcOpDataDto;

import com.csair.cbd.cbdinterface.services.dto.CancelDealResultDto;
import com.csair.cbd.cbdinterface.services.dto.DealResultDto;
import com.csair.cbd.ccs.services.web.Exception.WebServiceException;
import com.csair.cbd.ccs.services.web.datatype.MemberInfoDto;
import com.demo.entity.ConfigContent;
import com.demo.entity.BCTestCaseResultEntity;
import com.demo.source.TestDeleteCustomersRelationship;
import com.demo.source.TestFindCustomersBycode;
import com.demo.source.TestSaveCustomersBandRelationship;
import com.demo.source.TestUpdateCustomersPcvalue;
import com.demo.source.TestUpdateCustomersStarLever;

public class SVCBCSTestCases extends TestCase {

	public ConfigContent config;
	// 生成一个可读取的excel文件对象

	// excel记录
	private static int error = 0;

	// 辅助对象
	MemberInfoDto meberInfoDto;
	CancelDealResultDto cancelDealResultDto;
	DealResultDto dealResultDto;

	private static String useCaseId;
	private static long day1;
	private static long day2;
	private static long days;

	public SVCBCSTestCases(String string, ConfigContent configContent)
			throws IOException, RowsExceededException, WriteException {
		// TODO Auto-generated constructor stub
		super(string);
		this.config = configContent;

		/*
		 * if (workbook == null) {
		 * 
		 * String ddate = new SimpleDateFormat("ddHHmm").format(Calendar
		 * .getInstance().getTime());
		 * 
		 * System.out.println(config.getOutPath()); File xlsFile = new
		 * File(config.getOutPath()); System.out.println("xlsFile" + xlsFile);
		 * 
		 * workbook = Workbook.createWorkbook(xlsFile); // 添加工作表 passSheet =
		 * workbook.createSheet("用例汇总", 0); errorSheet =
		 * workbook.createSheet("校验错误", 1); exceptionSheet =
		 * workbook.createSheet("错误信息", 2); outPutSheet =
		 * workbook.createSheet("接口输出信息", 3);
		 * 
		 * exceptionSheet.addCell(new Label(0, 0, "用例ID"));
		 * exceptionSheet.addCell(new Label(1, 0, "错误信息"));
		 * exceptionSheet.setColumnView(0, 50); exceptionSheet.setColumnView(1,
		 * 50);
		 * 
		 * errorSheet.addCell(new Label(0, 0, "用例ID")); errorSheet.addCell(new
		 * Label(1, 0, "校验值")); errorSheet.addCell(new Label(2, 0, "输出值"));
		 * errorSheet.addCell(new Label(3, 0, "期望值"));
		 * errorSheet.setColumnView(0, 50); errorSheet.setColumnView(1, 15);
		 * errorSheet.setColumnView(2, 50); errorSheet.setColumnView(3, 50);
		 * 
		 * passSheet.addCell(new Label(0, 0, "用例ID")); passSheet.addCell(new
		 * Label(1, 0, "状态")); passSheet.addCell(new Label(2, 0, "耗时（毫秒）"));
		 * passSheet.setColumnView(0, 50); passSheet.setColumnView(1, 10);
		 * passSheet.setColumnView(2, 12);
		 * 
		 * outPutSheet.addCell(new Label(0, 0, "用例ID")); outPutSheet.addCell(new
		 * Label(1, 0, "异常")); outPutSheet.addCell(new Label(2, 0, "服务单号"));
		 * outPutSheet.addCell(new Label(3, 0, "交易ID"));
		 * outPutSheet.setColumnView(0, 50); outPutSheet.setColumnView(1, 50);
		 * outPutSheet.setColumnView(2, 20); outPutSheet.setColumnView(3, 15);
		 * 
		 * }
		 */

	}

	@Test
	public void saveCustomersBandRelationship() throws BiffException,
			IOException, RowsExceededException, WriteException {
		// 读取EXCEL
		File xls = new File(config.getInPath());
		jxl.Workbook book = Workbook.getWorkbook(xls.getAbsoluteFile());
		Sheet pay = book.getSheet("大客户接口数据池");

		//
		String[] payStr = new String[pay.getColumns()];
		getName(payStr, pay, 2);// 输入参数字段名

		int line = 3;

		// useCaseId = pay.getCell(0, line).getContents().toString();//用例编号
		String testOrNot = "是"; // = pay.getCell(1,
								// line).getContents().toString();//结果是否输出
		// String print = pay.getCell(2, line).getContents().toString();//结果是否输出
		useCaseId = getItem(pay, "数据编号", payStr, line);
		String mark = "test";

		List<BCTestCaseResultEntity> testCaseResultList = new ArrayList<BCTestCaseResultEntity>();
		BCTestCaseResultEntity testCaseResult;
		List<String> totalResult = new ArrayList<String>();
		while (!useCaseId.equals("") && useCaseId != null) {
			if (!mark.equals(useCaseId.substring(0, 5))) {
				testOrNot = pay.getCell(1, line).getContents().toString();
				if (mark != "test") {
					if (error == 0) {
						totalResult.add("OK");
					} else {
						totalResult.add("NG");
					}
				}
				error = 0;
				mark = useCaseId.substring(0, 5);
			}
			if (testOrNot.equals("是")) {
				String UID = getItem(pay, "UID", payStr, line);
				String pcValue = getItem(pay, "大客户级别", payStr, line);
				String bcCode = getItem(pay, "大客户号", payStr, line);

				SvcOpDataDto opDate = new SvcOpDataDto();
				opDate.setChannelId("B2B");
				opDate.setChannelIdPassword("999999");
				opDate.setOpId(getItem(pay, "操作人ID", payStr, line));

				try {
					/********************************/
					TestSaveCustomersBandRelationship testSaveCustomersBandRelationship = new TestSaveCustomersBandRelationship(
							config.getEnvironment());
					day1 = System.currentTimeMillis();
					String message = testSaveCustomersBandRelationship
							.testSaveCustomersBandRelationship(UID, pcValue,
									bcCode, opDate);
					day2 = System.currentTimeMillis();
					days = day2 - day1;
					/********************************/

					System.out.println(getItem(pay, "返回值", payStr, line));
					if (getItem(pay, "返回值", payStr, line).equals("绑定成功，返回Y")) {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(message);
						testCaseResult.setResult("OK");
					} else {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(message);
						testCaseResult.setResult("NG");
						error++;
					}
					testCaseResultList.add(testCaseResult);

				} catch (WebServiceException e) {

					if (checkResult("结果校验", e.getKey(),
							getItem(pay, "返回值", payStr, line))) {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.getKey());
						testCaseResult.setResult("OK");
					} else {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.getKey());
						testCaseResult.setResult("NG");
					}
					testCaseResultList.add(testCaseResult);

				} catch (Exception e) {
					if (checkResult("结果校验", e.toString().substring(60),
							getItem(pay, "返回值", payStr, line))) {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(getItem(pay, "返回值", payStr,
								line));
						testCaseResult.setResult("OK");
					} else {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.toString().substring(60));
						testCaseResult.setResult("NG");
					}
					testCaseResultList.add(testCaseResult);
				}

				// setCaseStatus();
			}
			useCaseId = getItem(pay, "数据编号", payStr, ++line);
			;// 用例编号

		}
		if (mark != "test") {
			if (error == 0) {
				totalResult.add("OK");
			} else {
				totalResult.add("NG");
			}
		}
		error = 0;

		book.close();
		writeDataSourceExcel(8, 3, testCaseResultList, 17, 10, totalResult);

	}

	@Test
	public void updateCustomersPcvalue() throws BiffException, IOException,
			RowsExceededException, WriteException {
		// 读取EXCEL
		File xls = new File(config.getInPath());
		jxl.Workbook book = Workbook.getWorkbook(xls.getAbsoluteFile());
		Sheet pay = book.getSheet("大客户接口数据池");

		//
		String[] payStr = new String[pay.getColumns()];
		getName(payStr, pay, 25);// 输入参数字段名

		int line = 26;

		// useCaseId = pay.getCell(0, line).getContents().toString();//用例编号
		String testOrNot = "是"; // = pay.getCell(1,
								// line).getContents().toString();//结果是否输出
		// String print = pay.getCell(2, line).getContents().toString();//结果是否输出
		useCaseId = getItem(pay, "数据编号", payStr, line);
		String mark = "test";

		List<BCTestCaseResultEntity> testCaseResultList = new ArrayList<BCTestCaseResultEntity>();
		BCTestCaseResultEntity testCaseResult;
		List<String> totalResult = new ArrayList<String>();
		while (!useCaseId.equals("") && useCaseId != null) {
			if (!mark.equals(useCaseId.substring(0, 5))) {
				testOrNot = pay.getCell(1, line).getContents().toString();
				if (mark != "test") {
					if (error == 0) {
						totalResult.add("OK");
					} else {
						totalResult.add("NG");
					}
				}
				error = 0;
				mark = useCaseId.substring(0, 5);
			}
			if (testOrNot.equals("是")) {
				String UID = getItem(pay, "UID", payStr, line);
				String pcValue = getItem(pay, "大客户级别", payStr, line);
				String bcCode = getItem(pay, "大客户号", payStr, line);

				SvcOpDataDto opDate = new SvcOpDataDto();
				opDate.setChannelId("B2B");
				opDate.setChannelIdPassword("999999");
				opDate.setOpId(getItem(pay, "操作人ID", payStr, line));

				try {
					/********************************/
					TestUpdateCustomersPcvalue testUpdateCustomersPcvalue = new TestUpdateCustomersPcvalue(
							config.getEnvironment());
					day1 = System.currentTimeMillis();
					String message = testUpdateCustomersPcvalue
							.testUpdateCustomersPcvalue(UID, pcValue, bcCode,
									opDate);
					day2 = System.currentTimeMillis();
					days = day2 - day1;
					/********************************/

					if (getItem(pay, "返回值", payStr, line).equals("修改绑定成功，返回Y")) {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(message);
						testCaseResult.setResult("OK");
					} else {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(message);
						testCaseResult.setResult("NG");
						error++;
					}
					testCaseResultList.add(testCaseResult);

				} catch (WebServiceException e) {

					if (checkResult("结果校验", e.getKey(),
							getItem(pay, "返回值", payStr, line))) {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.getKey());
						testCaseResult.setResult("OK");
					} else {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.getKey());
						testCaseResult.setResult("NG");
					}
					testCaseResultList.add(testCaseResult);

				} catch (Exception e) {
					System.out.println(e.toString().substring(59));
					if (checkResult("结果校验", e.toString().substring(60),
							getItem(pay, "返回值", payStr, line))) {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(getItem(pay, "返回值", payStr,
								line));
						testCaseResult.setResult("OK");
					} else {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.toString().substring(60));
						testCaseResult.setResult("NG");
					}
					testCaseResultList.add(testCaseResult);
				}

				// setCaseStatus();
			}
			useCaseId = getItem(pay, "数据编号", payStr, ++line);
			;// 用例编号

		}
		if (mark != "test") {
			if (error == 0) {
				totalResult.add("OK");
			} else {
				totalResult.add("NG");
			}
		}
		error = 0;

		book.close();

		writeDataSourceExcel(8, 26, testCaseResultList, 17, 17, totalResult);

	}

	@Test
	public void deleteCustomersRelationship() throws BiffException,
			IOException, RowsExceededException, WriteException {
		// 读取EXCEL
		File xls = new File(config.getInPath());
		jxl.Workbook book = Workbook.getWorkbook(xls.getAbsoluteFile());
		Sheet pay = book.getSheet("大客户接口数据池");

		//
		String[] payStr = new String[pay.getColumns()];
		getName(payStr, pay, 48);// 输入参数字段名

		int line = 49;

		// useCaseId = pay.getCell(0, line).getContents().toString();//用例编号
		String testOrNot = "是"; // = pay.getCell(1,
								// line).getContents().toString();//结果是否输出
		// String print = pay.getCell(2, line).getContents().toString();//结果是否输出
		useCaseId = getItem(pay, "数据编号", payStr, line);
		String mark = "test";

		List<BCTestCaseResultEntity> testCaseResultList = new ArrayList<BCTestCaseResultEntity>();
		BCTestCaseResultEntity testCaseResult;
		List<String> totalResult = new ArrayList<String>();
		while (!useCaseId.equals("") && useCaseId != null) {
			if (!mark.equals(useCaseId.substring(0, 5))) {
				testOrNot = pay.getCell(1, line).getContents().toString();
				if (mark != "test") {
					if (error == 0) {
						totalResult.add("OK");
					} else {
						totalResult.add("NG");
					}
				}
				error = 0;
				mark = useCaseId.substring(0, 5);
			}
			if (testOrNot.equals("是")) {
				String UID = getItem(pay, "UID", payStr, line);
				String bcCode = getItem(pay, "大客户号", payStr, line);

				SvcOpDataDto opDate = new SvcOpDataDto();
				opDate.setChannelId("B2B");
				opDate.setChannelIdPassword("999999");
				opDate.setOpId(getItem(pay, "操作人ID", payStr, line));

				try {
					/********************************/
					TestDeleteCustomersRelationship testDeleteCustomersRelationship = new TestDeleteCustomersRelationship(
							config.getEnvironment());
					day1 = System.currentTimeMillis();
					String message = testDeleteCustomersRelationship
							.testDeleteCustomersRelationship(UID, bcCode,
									opDate);
					day2 = System.currentTimeMillis();
					days = day2 - day1;
					/********************************/

					if (getItem(pay, "返回值", payStr, line).equals("修改绑定成功，返回Y")) {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(message);
						testCaseResult.setResult("OK");
					} else {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(message);
						testCaseResult.setResult("NG");
						error++;
					}
					testCaseResultList.add(testCaseResult);

				} catch (WebServiceException e) {

					if (checkResult("结果校验", e.getKey(),
							getItem(pay, "返回值", payStr, line))) {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.getKey());
						testCaseResult.setResult("OK");
					} else {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.getKey());
						testCaseResult.setResult("NG");
					}
					testCaseResultList.add(testCaseResult);

				} catch (Exception e) {
					System.out.println(e.toString().substring(60));
					if (checkResult("结果校验", e.toString().substring(60),
							getItem(pay, "返回值", payStr, line))) {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.toString().substring(60));
						testCaseResult.setResult("OK");
					} else {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.toString().substring(60));
						testCaseResult.setResult("NG");
					}
					testCaseResultList.add(testCaseResult);
				}

				// setCaseStatus();
			}
			useCaseId = getItem(pay, "数据编号", payStr, ++line);
			;// 用例编号

		}
		if (mark != "test") {
			if (error == 0) {
				totalResult.add("OK");
			} else {
				totalResult.add("NG");
			}
		}
		error = 0;

		book.close();

		writeDataSourceExcel(7, 49, testCaseResultList, 17, 24, totalResult);

	}

	@Test
	public void findCustomersBycode() throws BiffException, IOException,
			RowsExceededException, WriteException {
		// 读取EXCEL
		File xls = new File(config.getInPath());
		jxl.Workbook book = Workbook.getWorkbook(xls.getAbsoluteFile());
		Sheet pay = book.getSheet("大客户接口数据池");

		//
		String[] payStr = new String[pay.getColumns()];
		getName(payStr, pay, 67);// 输入参数字段名

		int line = 68;

		// useCaseId = pay.getCell(0, line).getContents().toString();//用例编号
		String testOrNot = "是"; // = pay.getCell(1,
								// line).getContents().toString();//结果是否输出
		// String print = pay.getCell(2, line).getContents().toString();//结果是否输出
		useCaseId = getItem(pay, "数据编号", payStr, line);
		String mark = "test";

		List<BCTestCaseResultEntity> testCaseResultList = new ArrayList<BCTestCaseResultEntity>();
		BCTestCaseResultEntity testCaseResult;
		List<String> totalResult = new ArrayList<String>();
		while (!useCaseId.equals("") && useCaseId != null) {
			if (!mark.equals(useCaseId.substring(0, 5))) {
				testOrNot = pay.getCell(1, line).getContents().toString();
				if (mark != "test") {
					if (error == 0) {
						totalResult.add("OK");
					} else {
						totalResult.add("NG");
					}
				}
				error = 0;
				mark = useCaseId.substring(0, 5);
			}
			if (testOrNot.equals("是")) {
				String bcCode = getItem(pay, "大客户号", payStr, line);

				SvcOpDataDto opDate = new SvcOpDataDto();
				opDate.setChannelId("B2B");
				opDate.setChannelIdPassword("999999");
				opDate.setOpId("999999");

				testCaseResult = new BCTestCaseResultEntity();

				testCaseResult.setSvcBigClientStatResultDtoIsNot(true);
				testCaseResult.setEmphasisNum("");
				testCaseResult.setSeniorNum("");
				testCaseResult.setStaffNum("");
				testCaseResult.setStaffTotal("");
				try {
					/********************************/
					TestFindCustomersBycode testFindCustomersBycode = new TestFindCustomersBycode(
							config.getEnvironment());
					day1 = System.currentTimeMillis();
					SvcBigClientStatResultDto message = testFindCustomersBycode
							.testFindCustomersBycode(bcCode, opDate);
					day2 = System.currentTimeMillis();
					days = day2 - day1;
					/********************************/

					testCaseResult.setEmphasisNum(message.getEmphasisNum());
					testCaseResult.setSeniorNum(message.getSeniorNum());
					testCaseResult.setStaffNum(message.getStaffNum());
					testCaseResult.setStaffTotal(message.getStaffTotal());

					if (getItem(pay, "返回值", payStr, line).equals("查询成功")) {
						testCaseResult.setMessage("查询成功");
						testCaseResult.setResult("OK");
					} else {
						testCaseResult.setMessage("查询失败");
						testCaseResult.setResult("NG");
						error++;
					}
					testCaseResultList.add(testCaseResult);

				} catch (WebServiceException e) {

					if (checkResult("结果校验", e.getKey(),
							getItem(pay, "返回值", payStr, line))) {

						testCaseResult.setMessage(e.getKey());
						testCaseResult.setResult("OK");
					} else {

						testCaseResult.setMessage(e.getKey());
						testCaseResult.setResult("NG");
					}
					testCaseResultList.add(testCaseResult);

				} catch (Exception e) {
					System.out.println(e.toString().substring(60));
					if (checkResult("结果校验", e.toString().substring(60),
							getItem(pay, "返回值", payStr, line))) {

						testCaseResult.setMessage(e.toString().substring(60));
						testCaseResult.setResult("OK");
					} else {

						testCaseResult.setMessage(e.toString().substring(60));
						testCaseResult.setResult("NG");
					}
					testCaseResultList.add(testCaseResult);
				}

				// setCaseStatus();
			}
			useCaseId = getItem(pay, "数据编号", payStr, ++line);
			;// 用例编号

		}
		if (mark != "test") {
			if (error == 0) {
				totalResult.add("OK");
			} else {
				totalResult.add("NG");
			}
		}
		error = 0;

		book.close();

		writeDataSourceExcel(8, 68, testCaseResultList, 17, 30, totalResult);

	}

	@Test
	public void updateCustomersStarLever() throws BiffException, IOException,
			RowsExceededException, WriteException {
		// 读取EXCEL
		File xls = new File(config.getInPath());
		jxl.Workbook book = Workbook.getWorkbook(xls.getAbsoluteFile());
		Sheet pay = book.getSheet("大客户接口数据池");

		//
		String[] payStr = new String[pay.getColumns()];
		getName(payStr, pay, 75);// 输入参数字段名

		int line = 76;

		// useCaseId = pay.getCell(0, line).getContents().toString();//用例编号
		String testOrNot = "是"; // = pay.getCell(1,
								// line).getContents().toString();//结果是否输出
		// String print = pay.getCell(2, line).getContents().toString();//结果是否输出
		useCaseId = getItem(pay, "数据编号", payStr, line);
		String mark = "test";

		List<BCTestCaseResultEntity> testCaseResultList = new ArrayList<BCTestCaseResultEntity>();
		BCTestCaseResultEntity testCaseResult;
		List<String> totalResult = new ArrayList<String>();
		while (!useCaseId.equals("") && useCaseId != null) {
			if (!mark.equals(useCaseId.substring(0, 5))) {
				testOrNot = pay.getCell(1, line).getContents().toString();
				if (mark != "test") {
					if (error == 0) {
						totalResult.add("OK");
					} else {
						totalResult.add("NG");
					}
				}
				error = 0;
				mark = useCaseId.substring(0, 5);
			}
			if (testOrNot.equals("是")) {
				String startLever = getItem(pay, "星级", payStr, line);
				String bcCode = getItem(pay, "大客户号", payStr, line);

				SvcOpDataDto opDate = new SvcOpDataDto();
				opDate.setChannelId("B2B");
				opDate.setChannelIdPassword("999999");
				opDate.setOpId(getItem(pay, "操作人ID", payStr, line));

				try {
					/********************************/
					TestUpdateCustomersStarLever testUpdateCustomersStarLever = new TestUpdateCustomersStarLever(
							config.getEnvironment());
					day1 = System.currentTimeMillis();
					String message = testUpdateCustomersStarLever
							.testUpdateCustomersStarLever(startLever, bcCode,
									opDate);
					day2 = System.currentTimeMillis();
					days = day2 - day1;
					/********************************/

					if (getItem(pay, "返回值", payStr, line).equals("修改星级成功，返回Y")) {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(message);
						testCaseResult.setResult("OK");
					} else {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(message);
						testCaseResult.setResult("NG");
						error++;
					}
					testCaseResultList.add(testCaseResult);

				} catch (WebServiceException e) {

					if (checkResult("结果校验", e.getKey(),
							getItem(pay, "返回值", payStr, line))) {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.getKey());
						testCaseResult.setResult("OK");
					} else {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.getKey());
						testCaseResult.setResult("NG");
					}
					testCaseResultList.add(testCaseResult);

				} catch (Exception e) {
					System.out.println(e.toString().substring(60));
					if (checkResult("结果校验", e.toString().substring(60),
							getItem(pay, "返回值", payStr, line))) {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.toString().substring(60));
						testCaseResult.setResult("OK");
					} else {
						testCaseResult = new BCTestCaseResultEntity();
						testCaseResult.setMessage(e.toString().substring(60));
						testCaseResult.setResult("NG");
					}
					testCaseResultList.add(testCaseResult);
				}

				// setCaseStatus();
			}
			useCaseId = getItem(pay, "数据编号", payStr, ++line);

		}
		if (mark != "test") {
			if (error == 0) {
				totalResult.add("OK");
			} else {
				totalResult.add("NG");
			}
		}
		error = 0;

		book.close();

		writeDataSourceExcel(7, 76, testCaseResultList, 17, 32, totalResult);

	}

	public void writeDataSourceExcel(int startline, int startline2,
			List<BCTestCaseResultEntity> list, int j, int k,
			List<String> totalResult) {
		// TODO Auto-generated method stub

		try {
			String inPath, outPath;
			if (!(new File(config.getOutPath()).exists())) {
				inPath = config.getInPath();
				outPath = config.getOutPath();
			} else {
				inPath = config.getOutPath();
				outPath = config.getOutPath();
			}

			HSSFWorkbook workbook = new HSSFWorkbook(
					new FileInputStream(inPath));

			HSSFSheet sheet = workbook.getSheet("大客户接口数据池");
			for (int i = 0; i < list.size(); i++) {

				if (list.get(i).isSvcBigClientStatResultDtoIsNot()) {

					HSSFRow row1 = sheet.getRow((short) startline2 + i);
					HSSFCell cell1 = row1.getCell((short) startline);
					cell1.setCellValue(list.get(i).getMessage());

					HSSFRow row2 = sheet.getRow((short) startline2 + i);
					HSSFCell cell2 = row2.getCell((short) startline + 1);
					cell2.setCellValue(list.get(i).getStaffTotal());

					HSSFRow row3 = sheet.getRow((short) startline2 + i);
					HSSFCell cell3 = row3.getCell((short) startline + 2);
					cell3.setCellValue(list.get(i).getSeniorNum());

					if (!(list.get(i).getEmphasisNum().equals("") || list
							.get(i).getEmphasisNum().equals(null))) {
						HSSFRow row4 = sheet.getRow((short) startline2 + i);
						HSSFCell cell4 = row4.getCell((short) startline + 3);
						cell4.setCellValue(list.get(i).getEmphasisNum());

					}

					HSSFRow row5 = sheet.getRow((short) startline2 + i);
					HSSFCell cell5 = row5.getCell((short) startline + 4);
					cell5.setCellValue(list.get(i).getResult());

				} else {
					HSSFRow row1 = sheet.getRow((short) startline2 + i);
					HSSFCell cell1 = row1.getCell((short) startline);
					HSSFRow row2 = sheet.getRow((short) startline2 + i);
					HSSFCell cell2 = row2.getCell((short) startline + 1);
					cell1.setCellValue(list.get(i).getMessage());
					cell2.setCellValue(list.get(i).getResult());
				}
			}

			HSSFSheet sheet1 = workbook.getSheet("大客户接口测试用例");
			for (int i = 0; i < totalResult.size(); i++) {
				HSSFRow row1 = sheet1.getRow((short) k + i);
				HSSFCell cell1 = row1.getCell((short) j);
				// System.out.println(cell1.getStringCellValue());
				// cell1.removeCellComment();
				if (cell1 == null) {
					cell1 = row1.createCell((short) j);
					// cell1.setCellStyle(style)
				}
				cell1.setCellValue(totalResult.get(i));
				// System.out.println(cell1.getStringCellValue());
			}

			FileOutputStream stream = new FileOutputStream(new File(outPath));
			workbook.write(stream);
			stream.close();

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

	/**
	 * 方法描述 : 取sheet页s中第line行的数据,赋值给字符串str
	 * 
	 * @输入参数 str指定的字符串,s驱动表中的页,line 行
	 * @输出参数
	 * @创建人及日期 : 2012/02/22 by 黄育莲
	 * @最后一次修改 :
	 */
	public void getName(String[] str, Sheet s, int line) {
		for (int i = 0; i < s.getColumns(); i++) {
			str[i] = s.getCell(i, line).getContents().toString();
		}
	}

	public String getItem(Sheet s, String name, String[] str, int lineNum) {
		String re = s.getCell(getColumn(name, str), lineNum).getContents()
				.toString();
		System.out.println(name + ":" + re);
		return re;

	}

	/**
	 * 方法描述 : 获取一字符在数组中的下标, 以此函数来获取指定字段名在excel文件中所在的列数
	 * 
	 * @输入参数 str指定的字符,data数组
	 * @输出参数 int指定字符在数组中的下标
	 * @创建人及日期 : 2012/02/22 by 黄育莲
	 * @最后一次修改 :
	 */
	public int getColumn(String str, String[] data) {
		int column = 0;
		for (int i = 0; i < data.length; i++) {
			if (str.equals(data[i])) {
				column = i;
				break;
			}
		}
		return column;
	}

	/**
	 * 校验接口输出与期望值
	 * 
	 * @param string
	 *            参数名
	 * @param output
	 *            输出
	 * @param expect
	 *            期望值
	 * @throws WriteException
	 * @throws RowsExceededException
	 */
	private boolean checkResult(Object string, Object output, Object expect)
			throws RowsExceededException, WriteException {
		// TODO Auto-generated method stub
		try {
			if (output instanceof String) {
				// if (!(expect.toString().equals("") ||
				// expect.toString().equals(
				// null))) {
				if (!output.toString().contains(expect.toString())) {

					/*
					 * errorSheet.addCell(new Label(0, totalError + 1,
					 * useCaseId)); errorSheet.addCell(new Label(1, totalError +
					 * 1, string .toString())); errorSheet.addCell(new Label(2,
					 * totalError + 1, output .toString()));
					 * errorSheet.addCell(new Label(3, totalError + 1, expect
					 * .toString()));
					 */

					error++;
					return false;

				}
				// }
			} else if (output instanceof Double || output instanceof Integer) {
				if (!(expect.toString().equals("") || expect.toString().equals(
						null))) {
					if (!output.toString().contains(expect.toString())) {
						/*
						 * errorSheet.addCell(new Label(0, totalError + 1,
						 * useCaseId)); errorSheet.addCell(new Label(1,
						 * totalError + 1, string .toString()));
						 * errorSheet.addCell(new Label(2, totalError + 1,
						 * output .toString())); errorSheet.addCell(new Label(3,
						 * totalError + 1, expect .toString()));
						 */

						error++;
						return false;

					}
				}
			} else {
				/*
				 * errorSheet.addCell(new Label(0, totalError + 1, useCaseId));
				 * errorSheet.addCell(new Label(1, totalError + 1, string
				 * .toString())); errorSheet.addCell(new Label(2, totalError +
				 * 1, "未能识别该数据类型:" + output.getClass().getName()));
				 * errorSheet.addCell(new Label(3, totalError + 1, expect
				 * .toString()));
				 */

				error++;
				return false;
			}
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

}
